# use normal make for this Makefile
#
# Makefile for building user programs to run on top of Nachos
#
# Several things to be aware of:
#
#    Nachos assumes that the location of the program startup routine (the
# 	location the kernel jumps to when the program initially starts up)
#       is at location 0.  This means: start.o must be the first .o passed 
# 	to ld, in order for the routine "Start" to be loaded at location 0
#

# If you are running on SunOS 5.x machines, uncomment the next line
GCCDIR = /auto/home-scf-22/csci402/testgnu/decstation-ultrix/bin/
LDFLAGS = -T newscript -N
ASFLAGS = -mips1
CPPFLAGS = $(INCDIR)

# if you aren't cross-compiling:
# GCCDIR =
# LDFLAGS = -N -T 0
# ASFLAGS =
# CPPFLAGS = -P $(INCDIR)


CC = $(GCCDIR)gcc
AS = $(GCCDIR)as
LD = $(GCCDIR)ld
CPP = $(GCCDIR)cpp

INCDIR =-I../userprog -I../threads
CFLAGS = -G 0 -c $(INCDIR)

all: halt matmult sort forktest forktest2 execTest Test1 Test2 threadLoadTest sendtest sendtest2

start.o: start.s ../userprog/syscall.h
	$(CPP) $(CPPFLAGS) start.s > strt.s
	$(AS) $(ASFLAGS) -o start.o strt.s
	rm strt.s

sendtest.o: sendtest.c
	$(CC) $(CFLAGS) -c sendtest.c
sendtest: sendtest.o start.o
	$(LD) $(LDFLAGS) start.o sendtest.o -o sendtest.coff
	../bin/coff2noff sendtest.coff sendtest

sendtest2.o: sendtest2.c
	$(CC) $(CFLAGS) -c sendtest2.c
sendtest2: sendtest2.o start.o
	$(LD) $(LDFLAGS) start.o sendtest2.o -o sendtest2.coff
	../bin/coff2noff sendtest2.coff sendtest2

halt.o: halt.c
	$(CC) $(CFLAGS) -c halt.c
halt: halt.o start.o
	$(LD) $(LDFLAGS) start.o halt.o -o halt.coff
	../bin/coff2noff halt.coff halt

execTest.o: execTest.c
	$(CC) $(CFLAGS) -c execTest.c
execTest: execTest.o start.o
	$(LD) $(LDFLAGS) start.o execTest.o -o execTest.coff
	../bin/coff2noff execTest.coff execTest

threadLoadTest.o: threadLoadTest.c
	$(CC) $(CFLAGS) -c threadLoadTest.c
threadLoadTest: threadLoadTest.o start.o
	$(LD) $(LDFLAGS) start.o threadLoadTest.o -o threadLoadTest.coff
	../bin/coff2noff threadLoadTest.coff threadLoadTest


sort.o: sort.c
	$(CC) $(CFLAGS) -c sort.c
sort: sort.o start.o
	$(LD) $(LDFLAGS) start.o sort.o -o sort.coff
	../bin/coff2noff sort.coff sort

matmult.o: matmult.c
	$(CC) $(CFLAGS) -c matmult.c
matmult: matmult.o start.o
	$(LD) $(LDFLAGS) start.o matmult.o -o matmult.coff
	../bin/coff2noff matmult.coff matmult

forktest.o: forktest.c
	$(CC) $(CFLAGS) -c forktest.c
forktest: forktest.o start.o
	$(LD) $(LDFLAGS) start.o forktest.o -o forktest.coff
	../bin/coff2noff forktest.coff forktest

forktest2.o: forktest2.c
	$(CC) $(CFLAGS) -c forktest2.c
forktest2: forktest2.o start.o
	$(LD) $(LDFLAGS) start.o forktest2.o -o forktest2.coff
	../bin/coff2noff forktest2.coff forktest2

Test1.o: Test1.c
	$(CC) $(CFLAGS) -c Test1.c
Test1: Test1.o start.o
	$(LD) $(LDFLAGS) start.o Test1.o -o Test1.coff
	../bin/coff2noff Test1.coff Test1

Test2.o: Test2.c
	$(CC) $(CFLAGS) -c Test2.c
Test2: Test2.o start.o
	$(LD) $(LDFLAGS) start.o Test2.o -o Test2.coff
	../bin/coff2noff Test2.coff Test2

clean:
	rm -f *.o *.coff
